import Init from './request';
export const uiwu = new Init({
    url: import.meta.env.VITE_BASE_URL,
    intercept: true,
    // routing: ['/pages/pointsmall/detail', '/pages/login/login', '/pages/login/privacy', '/pages/login/agreement', '/pages/login/outhlogin', '/pages/user/binding']
    routing: ['/pages/index/index', '/pages/account/login', '/pages/account/pwdforgot']
})



// 获取配置信息
export const getConfig = async (): Promise<any> => {
    return await uiwu.get({
        url: `config/data`
    })
}
/**
 * 获取播放token monitor/get_access_token
 */
export const get_access_token = async (): Promise<any> => {
    return await uiwu.get({
        url: `monitor/get_access_token`
    })
}
/**
 * 获取地区列表
 */
export const city_list = async (): Promise<any> => {
    return await uiwu.get({
        url: `city_list`
    })
}
/**
 * 获取短信验证码 send/verify
 */
export const sendVerify = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `send/verify`,
        data
    })
}
/**
 * wxLoain 微信授权登录
 * @property {Object} data 参数
 */
export const wxLoain = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `wechat/app_auth`,
        data
    })
}

/**
 * wxLoain 微信小程序授权登录
 * @property {Object} data 参数
 */
export const wxmpLoain = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `wechat/mini_auth`,
        data
    })
}

/**
 * appleLogin apple授权登录
 * @property {Object} data 参数
 */
export const appleLogin = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `apple/login`,
        data
    })
}


/**
 * TouTiaoLogin 抖音授权登录 douyin/login
 */
export const TouTiaoLogin = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `douyin/login`,
        data
    })
}
/**
 * 手机号码登录
 */
export const mobileLogin = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `login/mobile`,
        data
    })
}
/**
 * 微信授权手机号码 bind/wechat_mini/phone
 */
export const bindWechatPhone = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `bind/wechat_mini/phone`,
        data
    })
}
/**
 * 绑定邀请码 user/bind/spread
 */
export const bindMobile = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `user/bind/spread`,
        data
    })
}
/**
 * 获取个人信息
 */
export const userInfo = async (): Promise<any> => {
    return await uiwu.get({
        url: `user/userinfo`,
    })
}
/**
 * 获取消息通知列表message/list
 */
export const messagelist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `message/list`,
        data
    })
}
/**
 * 获取是否有未读消息 message/is_new
 */
export const messageIsNew = async (): Promise<any> => {
    return await uiwu.get({
        url: `message/is_new`,
    })
}
/**
 * 获取首页分类列表 category
 */
export const categoryIndex = async (): Promise<any> => {
    return await uiwu.get({
        url: `category`,
    })
}
/**
 *  获取首页奖品列表 productlist   product/list
 */
export const productlist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `product/list`,
        data
    })
}
/**
 * 获取零食机列表 device/list
 */
export const devicelist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `device/list`,
        data
    })
}
/**
 * productrandlist 首页奖品 随机列表  product/rand/list
 */
export const productrandlist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `product/rand/list`,
        data
    })
}

/**
 * addrepair 轮播图
 * @property {Object} data 参数
 */
export const bannerList = async (): Promise<any> => {
    return await uiwu.get({
        url: `banner`
    })
}

/**
 * 获取零食机商品详情 device/info/
 */
export const deviceinfo = async (id: string): Promise<any> => {
    return await uiwu.get({
        url: `device/info/${id}`
    })
}
/**
 * 切换零食机 device/rand/info/
 */
export const deviceRandInfo = async (id: string): Promise<any> => {
    return await uiwu.get({
        url: `device/rand/info/${id}`
    })
}
/**
 * startGren 开始游戏 grab/insert_coin
 */
export const startGren = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `grab/insert_coin`,
        data
    })
}
/**
 *  grabSubscribe 预约游戏 grab/subscribe
 */
export const grabSubscribe = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `grab/subscribe`,
        data
    })
}
/**
 * cancel_subscribe 取消预约 grab/cancel_subscribe
 */
export const cancel_subscribe = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `grab/cancel_subscribe`,
        data
    })
}
/**
 * forgo_subscribe 放弃游戏 grab/forgo_subscribe
 */
export const forgo_subscribe = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `grab/forgo_subscribe`,
        data
    })
}
/**
 * 休息了 grab/take_rest
 */
export const grabtakeRest = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `grab/take_rest`,
        data
    })
}
/**
 * grablist 游戏记录 grab/list
 */
export const grablist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `grab/list`,
        data
    })
}
/**
 * 申诉理由 grab/appeal/reason
 */
export const appealreason = async (): Promise<any> => {
    return await uiwu.get({
        url: `grab/appeal/reason`,
    })
}
/**
 * 提交申诉 grab/appeal
 */
export const grabappeal = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `grab/appeal`,
        data
    })
}


// 积分商品模块
/**
 * mallCategory 积分商品分类列表
 */
export const mallCategory = async (): Promise<any> => {
    return await uiwu.get({
        url: `integral/category/list`
    })
}
/**
 * goodslist 获取积分商品列表
 */
export const goodslist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `integral/product/list`,
        data
    })
}
/**
 * 积分商品详情
 */
export const goodsDetail = async (id: string | number): Promise<any> => {
    return await uiwu.get({
        url: `integral/product/info/${id}`
    })
}
/**
 * 创建积分订单 integral_order/create
 */
export const createOrder = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `integral_order/create`,
        data
    })
}
/**
 * 获取积分订单列表 zww.com/api/integral_order/list?state=0&page=1&limit=10
 */
export const integralOrderlist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `integral_order/list`,
        data
    })
}
/**
 * 获取积分订单详情 integral_order/info/
 */
export const integralOrderDetail = async (id: string | number): Promise<any> => {
    return await uiwu.get({
        url: `integral_order/info/${id}`
    })
}


//充值模块
/**
 * 获取充值套餐列表
 */
export const rechargelist = async (): Promise<any> => {
    return await uiwu.get({
        url: `recharge/index`
    })
}
/**
 * 获取充值可用优惠券列表 coupons/recharge
 */
export const rechargeCoupons = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `coupons/recharge`,
        data
    })
}
/**
 * 充值余额 recharge/recharge?recharge_id=177&coupon_user_id=1&pay_type=alipay
 */
export const rechargeRecharge = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `recharge/recharge`,
        data
    })
}
//个人中心模块
/**
 * useredit 修改用户信息 user/edit
 */
export const useredit = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `user/edit`,
        data
    })
}
/**
 * 获取用户默认头像列表user/system/avatar
 */
export const systemAvatar = async (): Promise<any> => {
    return await uiwu.get({
        url: `user/system/avatar`
    })
}
/**
 * 绑定手机号码 bind/phone
 */
export const bindPhone = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `bind/phone`,
        data
    })
}
/**
 * 更换手机号码 user/editPhone
 */
export const editPhone = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `user/editPhone`,
        data
    })
}
/**
 * 排行榜 grab_prize/ranking
 */
export const userRanking = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `grab_prize/ranking`,
        data
    })
}
/**
 * 新增收货地址
 */
export const addAddress = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `address/edit`,
        data
    })
}

/**
 * 获取地址列表 zww.com/api/address/list?page=1&limit=10
 */
export const addresslist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `address/list`,
        data
    })
}
/**
 * 删除收货地址 address/del
 */
export const delAddress = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `address/del`,
        data
    })
}
/**
 * 设置默认地址address/default/set
 */
export const setAddress = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `address/default/set`,
        data
    })
}
/**
 * 获取默认收货地址 address/default
 */
export const addressDefault = async (): Promise<any> => {
    return await uiwu.get({
        url: `address/default`
    })
}

/**
 * 我的优惠券列表 coupons/list?status=0&page=1&limit=10
 */
export const couponslist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `coupons/list`,
        data
    })
}
/**
 * 统计优惠券可用数量 coupons/count
 */
export const couponscount = async (): Promise<any> => {
    return await uiwu.get({
        url: `coupons/count`,
    })
}

/**
 * 任务列表 task/list
 */
export const tasklist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `task/list`,
        data
    })
}
/**
 * taskreceive 领取任务奖励task/receive
 */
export const taskreceive = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `task/receive`,
        data
    })
}
/**
 * 积分明细 user/integral/list
 */
export const integrallist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `user/integral/list`,
        data
    })
}
/**
 * 获取账户流水 user/now_money/list
 */
export const moneylist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `user/now_money/list`,
        data
    })
}
//分销中心
/**
 * 分销中心 user/distribution
 */
export const distribution = async (): Promise<any> => {
    return await uiwu.get({
        url: `user/distribution`
    })
}
/**
 * cashextract 申请提现 cash/extract
 */
export const cashextract = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `cash/extract`,
        data
    })
}
/**
 * 提现记录 cash/list
 */
export const cashlist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `cash/list`,
        data
    })
}

/**
 * integralOrderReceipt 确认收货积分订单 integral_order/receipt/
 */
export const integralOrderReceipt = async (data: number | string): Promise<any> => {
    return await uiwu.post({
        url: `integral_order/receipt/${data}`,
    })
}
/**
 * 积分申请售后 integral_order/apply/refund
 */
export const integralRefund = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `integral_order/apply/refund`,
        data
    })
}
/**
 * 粉丝列表 user/spread/people
 */
export const spreadpeople = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `user/spread/people`,
        data
    })
}
/**
 * 推广订单 user/brokerage/list
 */
export const brokeragelist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `user/brokerage/list`,
        data
    })
}
/**
 * 获取邀请海报 user/invite/poster
 */
export const invitePoster = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `user/invite/poster`,
        data
    })
}

/**
 * 常见问题 problem/list
 */
export const problemlist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `problem/list`,
        data
    })
}
/**
 * 问题详情
 */
export const probleminfo = async (id: string | number): Promise<any> => {
    return await uiwu.get({
        url: `problem/info/${id}`,
    })
}

/**
 * 平台政策 agreement?type=1
 * @param {string} type  类型：1-隐私政策，2-用户协议，3-游戏规则说明，4-积分规则
 */
export const agreement = async (type: string | number): Promise<any> => {
    return await uiwu.get({
        url: `agreement?type=${type}`,
    })
}

/**
 * sysConfig 系统音效设置 sys/config
 */
export const sysConfig = async (field: string = 'audio_link'): Promise<any> => {
    let url = '';
    // #ifdef WEB
    url = `&url=${encodeURIComponent(location.href.split('#')[0])}`;
    // #endif
    return await uiwu.get({
        url: `sys/config?field=${field}${url}`,
    })
}

/**
 * 会员权益列表 member/list
 */
export const memberlist = async (): Promise<any> => {
    return await uiwu.get({
        url: `member/list`,
    })
}
/**
 * 开通会员 member/activate
 */
export const memberActivate = async (data: object): Promise<any> => {
    return await uiwu.post({
        url: `member/activate`,
        data
    })
}
/**
 * memberrecirdlist 会员开通记录 member/activate/list
 */
export const memberrecirdlist = async (data: object): Promise<any> => {
    return await uiwu.get({
        url: `member/activate/list`,
        data
    })
}
/**
 * 注销账号 user/write_off
 */
export const writeOffLogin = async (): Promise<any> => {
    return await uiwu.get({
        url: `user/write_off`,
    })
}
/**
 * getAdPopup 弹窗广告 ad_pop
 */
export const getAdPopup = async (): Promise<any> => {
    return await uiwu.get({
        url: `ad_pop`,
    })
}

/**
 * 获取 广告位 task/ad
 */
export const taskAd = async (): Promise<any> => {
    return await uiwu.get({
        url: `task/ad`,
    })
}

// 获取问题
export const getQuestion = async (): Promise<any> => {
    return await uiwu.get({
        url: `question/bank`,
    })
}

// 回答问题
export const postQusetion = async (data: any): Promise<any> => {
    return await uiwu.post({
        url: `question/answer/${data.id}`,
        data
    })
}

// 获取底部菜单
export const getTaBbar = async (): Promise<any> => {
    return await uiwu.get({
        url: `bottom_tabbar`,
    })
}


// 获取个人中心菜单列表
export const getMenulist = async (): Promise<any> => {
    return await uiwu.get({
        url: `personal_menu`,
    })
}

// 设置青少年模式
export const setUserTeenage = async (data: any): Promise<any> => {
    return await uiwu.post({
        url: `user/teen`,
        data
    })
}

// 青少年模式忘记密码
export const apiTeenageForgotPwd = async (data: any): Promise<any> => {
    return await uiwu.post({
        url: `user/forget_teen_pwd`,
        data
    })
}

// 用户反馈
export const apiUserFeedBack = async (data: any): Promise<any> => {
    return await uiwu.post({
        url: `user/feedback/save`,
        data
    })
}

// 获取IOS充值路径
export const getIosRechargeUrl = async (): Promise<any> => {
    return await uiwu.get({
        url: `recharge_url/h5`,
    })
}

// 苹果支付校验支付状态
export const apiIosPayStatus = async (data: any): Promise<any> => {
    return await uiwu.post({
        url: `ios/pay/notify`,
        data
    })
}

export const wechatConfig = async (): Promise<any> => {
    return await uiwu.get({
        url: `wechat/config?url=${encodeURIComponent(location.href)}`
    })
}

export const wechatAuth = async (data: any): Promise<any> => {
    return await uiwu.get({
        url: `wechat/auth?code=${data.code}&spread_uid=${data.spread_uid}`
    })
}
